package com.ys.controller.api.storage;

import com.ys.config.MenuId;
import com.ys.entity.storage.TccTransportationType;
import com.ys.service.storage.TccTransportationTypeService;
import com.ys.service.sys.CommonApiService;
import com.ys.vo.LayuiTableVoJA;
import com.ys.vo.R;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Map;

/**
 * @Author: fxz
 * @CreateTime: 2024-12-05
 * @Description: 运输类型维护
 * @Version: 1.5
 */
@Controller
@RequestMapping("/api/inter/tccTransportationType")
public class ApiInterTccTransportationTypeController {
    private static final Logger logger = LoggerFactory.getLogger(ApiInterTccTransportationTypeController.class);
    
    @Autowired
    private TccTransportationTypeService tccTransportationTypeService;

    @Autowired
    private CommonApiService<TccTransportationType> commonApiService;

    //菜单id
    private Long menuId = MenuId.TCC_TransportationType;
    /**
     * 查询
     */
    @RequestMapping("/search")
    @ResponseBody
    public LayuiTableVoJA search(Model model, HttpServletRequest request, HttpServletResponse response,
                                 @ModelAttribute TccTransportationType cond, String conditions
    ){
        try {
            cond = setSeachSql(cond);
            LayuiTableVoJA setList = commonApiService.searchLay(cond);
            return setList;
        }catch (Exception e){
            logger.error("查询出错：",e.getMessage(),e);
            LayuiTableVoJA tableVoJA = new LayuiTableVoJA();
            tableVoJA.setCode(1);
            tableVoJA.setMsg("查询出错，请稍后重试！");
            return tableVoJA;
        }
    }



    /**
     * 设置查询的cond的sql设置
     * @param cond
     * @return
     */
    public TccTransportationType setSeachSql(TccTransportationType cond){

        cond
                //排序
                .setOrderby("A.Id DESC");

        cond = commonApiService.dataAuth(menuId, cond);
        return  cond;
    }


    @RequestMapping("/searchFbaPlan")
    @ResponseBody
    public LayuiTableVoJA searchFbaPlan(@ModelAttribute TccTransportationType cond){

        ;
        LayuiTableVoJA vo = commonApiService.searchLay(cond);
        return vo;
    }

    /**
     * 新增
     */
    @RequestMapping("/toAdd")
    @ResponseBody
    @RequiresPermissions("tccTransportationType:add")
    public R add(HttpServletRequest request, @RequestParam Map<String, Object> params,String subData) {
        try {
            //修改
            return tccTransportationTypeService.add(params,subData);
        } catch (Exception e) {
            e.printStackTrace();
            return R.error(e.getMessage());
        }
    }

    /**
     * 编辑
     */
    @RequiresPermissions("tccTransportationType:edit")
    @PostMapping("/toEdit")
    @ResponseBody
    public R edit(HttpServletRequest request,
                  @RequestParam Map<String, Object> params,String subData){
        try {
            return tccTransportationTypeService.edit(params, subData);
        } catch (Exception e) {
            e.printStackTrace();
            return R.error(e.getMessage());
        }
    }


}
